package com.ruoyi.web.controller.monitor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Demo;
import com.ruoyi.system.service.IDemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 用户测试Controller
 *
 * @author ruoyi
 * @date 2024-11-27
 */
@RestController
@RequestMapping("/user/demo")
@Api(value = "用户测试控制器", tags = {"用户测试管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class DemoController extends BaseController {

    @Autowired
    private final IDemoService demoService;

    /**
     * 查询用户测试列表
     */
    @ApiOperation("查询用户测试列表")
    @PreAuthorize("@ss.hasPermi('system:demo:list')")
    @GetMapping("/list")
    public TableDataInfo list(Demo demo) {
        startPage();
        List<Demo> list = demoService.list(new QueryWrapper<Demo>(demo));
        return getDataTable(list);
    }

    /**
     * 导出用户测试列表
     */
    @ApiOperation("导出用户测试列表")
    @PreAuthorize("@ss.hasPermi('system:demo:export')")
    @Log(title = "用户测试", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Demo demo) {
        List<Demo> list = demoService.list(new QueryWrapper<Demo>(demo));
        ExcelUtil<Demo> util = new ExcelUtil<Demo>(Demo.class);
        return util.exportExcel(list, "用户测试数据");
    }

    /**
     * 获取用户测试详细信息
     */
    @ApiOperation("获取用户测试详细信息")
    @PreAuthorize("@ss.hasPermi('system:demo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(demoService.getById(id));
    }

    /**
     * 新增用户测试
     */
    @ApiOperation("新增用户测试")
    @PreAuthorize("@ss.hasPermi('system:demo:add')")
    @Log(title = "用户测试", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Demo demo) {
        return toAjax(demoService.save(demo));
    }

    /**
     * 修改用户测试
     */
    @ApiOperation("修改用户测试")
    @PreAuthorize("@ss.hasPermi('system:demo:edit')")
    @Log(title = "用户测试", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Demo demo) {
        return toAjax(demoService.updateById(demo));
    }

    /**
     * 删除用户测试
     */
    @ApiOperation("删除用户测试")
    @PreAuthorize("@ss.hasPermi('system:demo:remove')")
    @Log(title = "用户测试", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(demoService.removeByIds(Arrays.asList(ids)));
    }
}
